package org.ddevil.data.set;

import java.util.Comparator;

import org.ddevil.data.Data;
import org.ddevil.data.SortOrder;


/**
 * This interface describes a DataSet with the additional functionality of
 * sorting.
 * <p>
 *
 * @author Rich O'Connell
 */
public interface SortableDataSet<T extends Data> extends DataSet<T> {

	/**
	 * A data type that holds info about a sort.
	 */
	static public class SortInfo {
		/** The DB Id of the attribute that this sort is applied to. */
		public String dbIdentifier;

		/** The depth of this sort. */
		public int depth;

		/**
		 * The type of this sort.
		 *
		 * @see SortOrder
		 */
		public SortOrder type;

		public SortInfo(String dbId, SortOrder type, int depth) {
			this.dbIdentifier = dbId;
			this.type = type;
			this.depth = depth;
		}
	}

	/**
	 * Set the {@link Comparator} to use for the given class. When sorting an
	 * attribute whose values are stored using the given class, the given
	 * Comparator will be used.
	 *
	 * @param className
	 *            The Class type to use this comparator on.
	 * @param myComparator
	 *            The Comparator to use.
	 */
	public abstract void setComparator(Class className, Comparator myComparator);

	/**
	 * Set a special {@link Comparator} to use for an attribute. Setting a
	 * Comparator for an attribute doesn't apply a sort to the DataSet.
	 * {@link #setSort(String, SortOrder)} must be called on the attribute for a
	 * sort to actually be applied.
	 *
	 * @param dbId
	 *            The attribute to apply this comparator to.
	 * @param myComparator
	 */
	public abstract void setComparator(String dbId, Comparator myComparator);

	/**
	 * Apply a sort for the given attribute. Supplying <code>null</code> or
	 * {@link SortOrder#NONE} for the sortOrder parameter will remove the sort
	 * from that attribute.
	 *
	 * @param dbId
	 *            The attribute to sort.
	 * @param sortOrder
	 *            The type of sort to be applied.
	 */
	public abstract void setSort(String dbId, SortOrder sortOrder);

	/**
	 * Get information about the current sort for a particular attribute.
	 *
	 * @param dbid
	 *            The attribute to get info for.
	 * @return A SortInfo object containing the information about that sort.
	 * @see SortInfo
	 */
	public abstract SortInfo getSortInfo(String dbid);

	/**
	 * Remove all sorts on this DataSet.
	 */
	public abstract void clearAllSorts();

	/**
	 * Sets whether this data set is currently sorting its wrapped dataset. Used
	 * for batch updates by index.
	 *
	 * @param sortEnabled
	 */
	public void setSortEnabled(boolean sortEnabled);

	/**
	 * Use this method if multiple indices must be removed.
	 *
	 * @param indices
	 */
	public void removeRecords(int... indices);

}